#include <stdio.h>

typedef struct
{
    void* data;
    size_t elem_size;
    int type_id;
} GenericContainer;

void print_container(GenericContainer* c)
{
    if(c->type_id == 0)
        printf("Integer: %d\n", *(int *)c->data);
    else if (c->type_id == 1)
        printf("Double: %.2f\n", *(double *)c->data);
}


/**
 * 指针实现动态类型安全容器
*/
int main(int argc, char const *argv[])
{
    int x = 42;
    GenericContainer ibox = {&x, sizeof(int), 0};
    print_container(&ibox);

    double y = 3.14;
    GenericContainer dbox = {&y, sizeof(double), 1};
    print_container(&dbox);
       
    return 0;
}